package com.itmuch.cloud.microserviceconsumermovie.feign;

import com.itmuch.cloud.microserviceconsumermovie.entity.User;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/********************************************************
 *@Desc: feign客户端使用
 *
 * 使用feign两个坑
 * 1、不支持GetMapping
 * 2、@PathVariable必须自定value
 * 3、如果参数是一个对象，必须用post请求，如果多个参数，必须分开写
 *@Author: ZRP
 *@Date: 2017/12/20 14:00
 ********************************************************/
@FeignClient(name = "microservice-provider-user", fallback = UserFeignClient.HystrixClientFallBack.class)
public interface UserFeignClient {

    @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET)
    public User findById(@PathVariable("id") Long id);


    @Component
    static class HystrixClientFallBack implements UserFeignClient{
        @Override
        public User findById(Long id) {
            System.out.println("============fallback===============");
            User user = new User();
            user.setId(0L);
            return user;
        }
    }
}
